package com.example.recycler.clipchildren;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class ActivityMainAdapter extends BaseAdapter {

    private   List<String> mStrings=new ArrayList<>();

    private Context mContext;
    private LayoutInflater layoutInflater;

    public ActivityMainAdapter(Context context) {
        this.mContext = context;
        this.layoutInflater = LayoutInflater.from(context);
        for(int i='A';i<='Z';i++){
            mStrings.add("数据"+i);
        }
    }

    @Override
    public int getCount() {
        return mStrings.size();
    }

    @Override
    public String getItem(int position) {
        return mStrings.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder=null;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.list_view, parent,false);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) convertView.getTag();
        }
        String s=this.getItem(position);
        viewHolder.mListTv.setText(s.toString());
//        convertView.setOnClickListener(this);
//        viewHolder.mListTv.setOnClickListener(this);

        return convertView;
    }

    private void initializeViews(String entity, ViewHolder holder,int position) {

    }

//    @Override
//    public void onClick(View view) {
//        Toast.makeText(mContext, "点到了tv", Toast.LENGTH_SHORT).show();
//    }

    protected class ViewHolder {
        private ImageView mImgList;
        private TextView mListTv;
        private Button mBtList;



        public ViewHolder(View view) {
            mImgList = (ImageView) view.findViewById(R.id.img_list);
            mListTv = (TextView) view.findViewById(R.id.list_tv);
            mBtList = (Button) view.findViewById(R.id.bt_list);

        }
    }
}
